package com.yanqu.road.entity.activity.springdraw.data;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.activity.springdraw.enums.SpringDrawPassTypeEnum;
import com.yanqu.road.utils.property.Property;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@FieldTypeAnnotation(tableName = "t_u_spring_draw_user_data")
public class SpringDrawUserData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "玩家ID", select = true, update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "当前关卡")
    private int level;

    @FieldTypeAnnotation(desc = "总浇灌次数")
    private int drawNum;

    @FieldTypeAnnotation(desc = "当前关卡棋盘二位数组")
    private int[][] board;

    @FieldTypeAnnotation(desc = "当前关卡棋盘创建时间")
    private long boardCreateTime;

    @FieldTypeAnnotation(desc = "是否过关")
    private int passFlag;

    @FieldTypeAnnotation(desc = "积分")
    private long score;

    @FieldTypeAnnotation(desc = "自选奖励")
    private Map<Integer, String> selfSelectRewardMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "创建时间")
    private long createTime;

    public SpringDrawUserData(int activityId, long userId, int[][] board) {
        this.activityId = activityId;
        this.userId = userId;
        this.level = 1;
        this.drawNum = 0;
        this.board = board;
        this.passFlag = SpringDrawPassTypeEnum.SPRING_DRAW_PASS_NOT.getType();
        this.boardCreateTime = System.currentTimeMillis();
        this.score = 0;
        this.createTime = System.currentTimeMillis();
        this.setInsertOption();
    }

    public SpringDrawUserData() {}

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        if(this.level != level) {
            this.level = level;
            setUpdateOption();
        }
    }

    public int[][] getBoard() {
        return board;
    }

    public void setBoard(int[][] board) {
        if(this.board != board) {
            this.board = board;
            setUpdateOption();
        }
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        if(this.createTime != createTime) {
            this.createTime = createTime;
            setUpdateOption();
        }
    }

    public int getDrawNum() {
        return drawNum;
    }

    public void setDrawNum(int drawNum) {
        if(this.drawNum != drawNum) {
            this.drawNum = drawNum;
            setUpdateOption();
        }
    }

    public long getBoardCreateTime() {
        return boardCreateTime;
    }

    public void setBoardCreateTime(long boardCreateTime) {
        if (this.boardCreateTime != boardCreateTime) {
            this.boardCreateTime = boardCreateTime;
            setUpdateOption();
        }
    }

    public int getPassFlag() {
        return passFlag;
    }

    public void setPassFlag(int passFlag) {
        if (this.passFlag != passFlag) {
            this.passFlag = passFlag;
            setUpdateOption();
        }
    }

    public Map<Integer, String> getSelfSelectRewardMap() {
        return this.selfSelectRewardMap;
    }

    public void putSelfSelectRewardMap(int level, String reward) {
        this.selfSelectRewardMap.put(level, reward);
        setUpdateOption();
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        if (this.score != score) {
            this.score = score;
            setUpdateOption();
        }
    }

    /**
     * 增加积分
     * @param addScore
     */
    public synchronized void addScore(long addScore) {
        this.score += addScore;
        setUpdateOption();
    }
}
